local RED = {255,0,0,255}
local DARKRED = {100,0,0,255}
local WHITE = {255,255,255,255}

Resource = {
	Sheet = nil,
	TileSize = {w=16,h=16}
}
function Resource.load()
	Resource.Sheet = sheet
	
	--compile assets
	for k,v in pairs(ITEMS) do
		v.inv = Resource.getAssetID(unpack(v[1]))
		v.Source = lib.GetTileByIndex(Resource.Sheet, v.inv, Resource.TileSize.w,Resource.TileSize.h)
	end
end
function Resource.getAsset(x,y)
	return x*Resource.TileSize.x,y*Resource.TileSize.y, 
			Resource.TileSize.x,Resource.TileSize.y
end
function Resource.getAssetID(x,y)
	local maxcol = math.floor(Resource.Sheet:getWidth() / Resource.TileSize.w)
	local maxrow = math.floor(Resource.Sheet:getHeight() / Resource.TileSize.h)
	return y*maxcol + x
end

local ID = Resource.getAssetID
ITEMS = {
	note = 				{{6,0}, c = WHITE},
	noteBlock = 		{{7,0}, c = WHITE},
	redDustOff = 		{{2,6}, c = DARKRED},
	redDustOn = 			{{2,6}, c = RED},
	redCrossOff = 		{{3,6}, c = DARKRED},
	redCrossOn = 			{{3,6}, c = RED},
	redTorchOff = 		{{2,5}, c = DARKRED},
	redTorchOn = 			{{2,5}, c = RED},
	redTorchRod = 		{{3,5}, c = WHITE},
	
	blockSolid = 		{{0,2}, c = WHITE},
	blockSand =			{{5,0}, c = WHITE},
	blockGlass =		{{5,1}, c = WHITE},
	woolGray =			{{0,0}, c = WHITE},
	woolDarkGray =		{{0,1}, c = WHITE},
	woolRed = 			{{1,0}, c = WHITE},
	woolGreen = 		{{2,0}, c = WHITE},
	woolBlue = 			{{3,0}, c = WHITE},
	woolMagenta =		{{1,1}, c = WHITE},
	woolYellow =		{{2,1}, c = WHITE},
	woolCyan =			{{3,1}, c = WHITE},
	
	normalPiston = 		{{4,4}, c = WHITE},
	normalPistonUp =	{{4,7}, c = WHITE},
	normalPistonDown=	{{6,7}, c = WHITE},
	normalPistonRod = 	{{4,5}, c = WHITE},
	pistonBaseOn = 		{{4,6}, c = WHITE},
	stickyPiston = 		{{5,4}, c = WHITE},
	stickyPistonUp = 	{{5,7}, c = WHITE},
	stickyPistonDown =	{{7,7}, c = WHITE},
	stickyPistonRod = 	{{5,5}, c = WHITE},
	
	woodTouchpadOff = 	{{3,2}, c = WHITE},
	woodTouchpadOn = 	{{3,3}, c = WHITE},
	woodTouchpadFloor=	{{2,2}, c = WHITE},
	stoneTouchpadOff =	{{4,2}, c = WHITE},
	stoneTouchpadOn = 	{{4,3}, c = WHITE},
	stoneTouchpadFloor=	{{2,3}, c = WHITE},
	
	leverOn = 			{{5,2}, c = WHITE},
	leverOff = 			{{5,3}, c = WHITE},
	leverSideOff = 		{{0,5}, c = WHITE},
	leverSideOn = 		{{1,5}, c = WHITE},
	
	buttonOff = 		{{0,3}, c = WHITE},
	buttonOn = 			{{1,3}, c = WHITE},
	diode1	= 			{{6,6}, c = WHITE},
	diode2	= 			{{6,5}, c = WHITE},
	diode3	= 			{{6,4}, c = WHITE},
	diode4	= 			{{6,3}, c = WHITE},
	diodeSide1	= 		{{7,6}, c = WHITE},
	diodeSide2	= 		{{7,5}, c = WHITE},
	diodeSide3	= 		{{7,4}, c = WHITE},
	diodeSide4	= 		{{7,3}, c = WHITE},
	
	woodDoor1 =			{{8,7}, c = WHITE},
	ironDoor1 =			{{10,7}, c = WHITE},
	woodLatch =			{{9,2}, c = WHITE},
}